<template>
	<ui-select
		v-model="innerValue"
		:items="options"
		text-field="name"
		value-field="value"
		:placeholder="placeholder"
	></ui-select>
</template>

<script>
	export default {
		name: 'BiDynamicFormControlDropdown',
		props: {
			/**
			 * {
			 * 		name: '',
			 * 		value: ''
			 * }
			 * */
			value: {
				type: Object
			},
			schema: {
				type: Object
			}
		},
		computed: {
			innerValue: {
				get () {
					let value
					if (this.value) {
						value = this.value.value
					}
					return value
				},
				set (val) {
					const opt = this.options.find(v => v.value === val)
					if (opt) {
						this.$emit('input', {
							name: opt.name,
							value: opt.value
						})
					} else {
						this.$emit('input', null)
					}
				}
			},
			placeholder () {
				return this.schema.placeholder || '请选择'
			},
			options () {
				return this.schema.items || []
			}
		}
	}
</script>

<style>
</style>
